package mark.tom.pistols.encryptor;

import java.util.List;

import mark.tom.pistols.algorithm.encryption.Base64Encryption;
import mark.tom.pistols.model.SecurityModelProto;

public final class KeyChainMixer {

    public static String getKeyChainInfo(List<String> fileNames, String priKey, String method, String extParam) throws Exception {
        if (null == fileNames || fileNames.size() == 0) {
            return null;
        }
        SecurityModelProto.SecurityModel.Builder securityModelBuilder = SecurityModelProto.SecurityModel.newBuilder();
        for (String fileName : fileNames) {
            securityModelBuilder.addInclude(SecurityModelProto.SecurityModel.EncryptFile.newBuilder().setName(fileName).build());
        }
        securityModelBuilder.setDecryptKey(new StringBuilder(priKey).reverse().toString());
        securityModelBuilder.setMethod(method);
        securityModelBuilder.setExtParam(extParam);
        SecurityModelProto.SecurityModel securityModel = securityModelBuilder.build();
        return new String(Base64Encryption.encrypt(securityModel.toByteArray()), "utf-8");
    }

}
